<template>
  <nav-bar class="nav-bar">

    <template #left>
      <div @click="backClick"><svg-icon iconName="back" className=""></svg-icon></div>
    </template>

    <template #center>
      <div v-for="(item,index) in titles" 
      :key="index"
      class="nav-bar-item"
      @click="itemClick(index)"
      :class="{active: index == currentIndex}"
      >
        {{ item }}
      </div>
    </template>

  </nav-bar>
</template>

<script>
import NavBar from 'components/common/navbar/NavBar'

export default {
  name: 'DetailNavBar',
  data() {
    return {
      currentIndex: 0,
      titles: ['商品','参数','评论','推荐']
    }
  },
  components: {
    NavBar,
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index,
      this.$emit('tabClick', index)
    },
    backClick() {
      this.$router.back()
    }
  },
}
</script>

<style scoped>
.nav-bar {
  display: flex;
}
.nav-bar-item {
  flex: 1;
}
.active {
  color: red;
}
</style>